package com.fesine.cas.util;

import org.jasig.cas.client.authentication.AttributePrincipal;
import org.jasig.cas.client.util.AbstractCasFilter;
import org.jasig.cas.client.validation.Assertion;

import javax.servlet.http.HttpServletRequest;

/**
 * @description: 类描述
 * @author: Fesine
 * @createTime:2017/12/13
 * @update:修改内容
 * @author: Fesine
 * @updateTime:2017/12/13
 */
public class CASUtil {
    /**
     * 从cas中获取用户名
     *
     * @param request
     * @return
     */
    public static String getAccountNameFromCas(HttpServletRequest request) {
        Assertion assertion = (Assertion) request.getSession().getAttribute(AbstractCasFilter
                .CONST_CAS_ASSERTION);
        AttributePrincipal principal = assertion.getPrincipal();
        return principal.getName();
    }
}
